import { requestClient } from '#/api/request';

/**
 * OAuth2 客户端信息
 */
export interface OAuth2Client {
  id: string;
  clientId: string;
  clientSecret?: string;
  clientName: string;
  clientAuthenticationMethods?: string;
  authorizationGrantTypes?: string;
  redirectUris?: string;
  scopes?: string;
  clientSettings?: string;
  tokenSettings?: string;
  createdAt?: string;
  updatedAt?: string;
}

/**
 * OAuth2 客户端 DTO
 */
export interface OAuth2ClientDTO {
  id: string;
  clientId: string;
  clientSecret?: string;
  clientName: string;
  clientAuthenticationMethods?: string[];
  authorizationGrantTypes?: string[];
  redirectUris?: string[];
  scopes?: string[];
  clientSettings?: any;
  tokenSettings?: any;
  createdAt?: string;
  updatedAt?: string;
}

/**
 * OAuth2 客户端创建请求
 */
export interface OAuth2ClientCreateRequest {
  clientId: string;
  clientSecret?: string;
  clientName: string;
  clientAuthenticationMethods?: string[];
  authorizationGrantTypes?: string[];
  redirectUris?: string[];
  scopes?: string[];
  clientSettings?: any;
  tokenSettings?: any;
}

/**
 * OAuth2 客户端更新请求
 */
export interface OAuth2ClientUpdateRequest {
  clientName?: string;
  clientSecret?: string;
  clientAuthenticationMethods?: string[];
  authorizationGrantTypes?: string[];
  redirectUris?: string[];
  scopes?: string[];
  clientSettings?: any;
  tokenSettings?: any;
}

/**
 * OAuth2 客户端查询参数
 */
export interface OAuth2ClientQueryParams {
  pageNum?: number;
  pageSize?: number;
  clientId?: string;
  clientName?: string;
}

/**
 * 分页结果
 */
export interface OAuth2ClientPageResult {
  records: OAuth2ClientDTO[];
  total: number;
  current: number;
  size: number;
}

/**
 * 选项类型
 */
export interface OptionItem {
  value: string;
  label: string;
}

/**
 * 分页查询 OAuth2 客户端列表
 */
export async function getOAuth2ClientListApi(params: OAuth2ClientQueryParams) {
  return requestClient.get<OAuth2ClientPageResult>('/auth/api/oauth2/clients', {
    params,
  });
}

/**
 * 根据 ID 查询 OAuth2 客户端详情
 */
export async function getOAuth2ClientByIdApi(id: string) {
  return requestClient.get<OAuth2ClientDTO>(`/auth/api/oauth2/clients/${id}`);
}

/**
 * 创建 OAuth2 客户端
 */
export async function createOAuth2ClientApi(data: OAuth2ClientCreateRequest) {
  return requestClient.post<OAuth2ClientDTO>('/auth/api/oauth2/clients', data);
}

/**
 * 更新 OAuth2 客户端
 */
export async function updateOAuth2ClientApi(id: string, data: OAuth2ClientUpdateRequest) {
  return requestClient.put<OAuth2ClientDTO>(`/auth/api/oauth2/clients/${id}`, data);
}

/**
 * 删除 OAuth2 客户端
 */
export async function deleteOAuth2ClientApi(id: string) {
  return requestClient.delete<void>(`/auth/api/oauth2/clients/${id}`);
}

/**
 * 批量删除 OAuth2 客户端
 */
export async function batchDeleteOAuth2ClientsApi(ids: string[]) {
  return requestClient.delete<void>('/auth/api/oauth2/clients/batch', {
    data: ids,
  });
}

/**
 * 获取所有可用的授权类型
 */
export async function getGrantTypesApi() {
  return requestClient.get<OptionItem[]>('/auth/api/oauth2/clients/getGrantTypes');
}

/**
 * 获取所有可用的客户端认证方法
 */
export async function getAuthMethodsApi() {
  return requestClient.get<OptionItem[]>('/auth/api/oauth2/clients/getAuthMethods');
}

/**
 * 获取所有可用的权限范围
 */
export async function getScopesApi() {
  return requestClient.get<OptionItem[]>('/auth/api/oauth2/clients/getScopes');
}

